package com.easy.controller;

import com.easy.bean.Quality_inspection;
import com.easy.service.QualityInspectionService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/quality_inspection")
public class QualityInspectionController {

    @Autowired
    private QualityInspectionService qualityInspectionService;

    // 新增
    @PostMapping
    public Result add(@RequestBody Quality_inspection inspection) {
        return Result.success(qualityInspectionService.add(inspection));
    }

    // 编辑
    @PutMapping("/{id}")
    public Result edit(@PathVariable("id") Integer id, @RequestBody Quality_inspection inspection) {
        inspection.setId(id);
        return Result.success(qualityInspectionService.edit(inspection));
    }

    // 删除
    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Integer id) {
        return Result.success("删除数据", qualityInspectionService.del(id));
    }

    // 查询所有（可模糊查询）
    @GetMapping
    public Result all(
            @RequestParam(name = "production_order_id", required = false) Integer productionOrderId,
            @RequestParam(name = "purchase_order_id", required = false) Integer purchaseOrderId,
            @RequestParam(name = "inspector_id", required = false) Integer inspectorId
    ) {
        return Result.success(qualityInspectionService.all(productionOrderId, purchaseOrderId, inspectorId));
    }

    // 查询单个
    @GetMapping("/{id}")
    public Result one(@PathVariable("id") Integer id) {
        return Result.success(qualityInspectionService.one(id));
    }

    // 分页查询
    @GetMapping("page")
    public Result page(Page page, Quality_inspection inspection){
        qualityInspectionService.page(page, inspection);
        return Result.success(page);
    }
}